home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / info / ti733.zip / TI733.TXT
Text File  |  1992-08-12  |  4KB  |  46 lines

  1.  
  2. PRODUCT  :  Borland C++                            NUMBER  :  733             
  3. VERSION  :  2.0                                                               
  4. OS  :  DOS                                                                    
  5. DATE  :  February 25, 1992                        PAGE  :  1/1                
  6.                                                                               
  7. TITLE  :  How to Use Variable Arguments                                       
  8.                                                                               
  9.                                                                               
  10.                                                                               
  11.                                                                               
  12.                                                                               
  13.                                                                               
  14.                                                                               
  15. /*************************************************************                
  16. Example code for using a variable number of arguments.                        
  17. There is only one guaranteed way of accessing arguments passed                
  18. using the ... mechanism.  The standard header file <stdarg.h> as              
  19. specified for ANSI C will provide declarations that can be used               
  20. by a function that does not know the number or types of its                   
  21. arguments when it is compiled.                                                
  22. *************************************************************/                
  23.                                                                               
  24. #include <stdarg.h>                                                           
  25. void real_handler(const char*, va_list);                                      
  26. void my_error_handler(const char* format ...)                                 
  27. {                                                                             
  28. // ...                                                                        
  29. va_list ap;                                                                   
  30. va_start(ap,format);                                                          
  31. real_handler(format,ap);  /* get arguments */                                 
  32. va_end(ap);                                                                   
  33. exit(99);                                                                     
  34. }                                                                             
  35.                                                                               
  36. void real_handler(const char* format, va_list ap)                             
  37. {                                                                             
  38. // assume that 'format' tells us that                                         
  39. // three arguments, a char*, an int, and a double,                            
  40. // are passed - in that order - by the va_list 'ap'                           
  41. char* p = va_arg(ap,char*);                                                   
  42. int i = va_arg(ap,int);                                                       
  43. double d = va_arg(ap,double);                                                 
  44. }                                                                             
  45.                                                                               
  46.